package org.scut.gis.spider.service;

import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableScheduledFuture;
import org.scut.gis.spider.data.enums.SupportLanguageEnum;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.List;

public class EngineService {

    public static List<ScriptEngine> engines;
    public static ScriptEngineManager scriptEngineManager;

    public static void init() {
        // init script engine manager.
        scriptEngineManager = new ScriptEngineManager();

        engines = Lists.newArrayListWithCapacity(SupportLanguageEnum.values().length);
        ScriptEngine engine;

        // add python script engine.
        engine = scriptEngineManager.getEngineByName(SupportLanguageEnum.PYTHON.getLanguage());
        if (engine != null) {
            engines.add(engine);
        }

        // add Kotlin Script Engine.
        engine = scriptEngineManager.getEngineByName(SupportLanguageEnum.KOTLIN.getLanguage());
        if (engine != null) {
            engines.add(engine);
        }

        // add Groovy Script Engine.
        engine = scriptEngineManager.getEngineByName(SupportLanguageEnum.GROOVY.getLanguage());
        if (engine != null) {
            engines.add(engine);
        }

        // add JavaScript Engine.
        engine = scriptEngineManager.getEngineByName(SupportLanguageEnum.JAVA_SCRIPT.getLanguage());
        if (engine != null) {
            engines.add(engine);
        }
    }
}
